package sg.com.techstudio.ecc.obj;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="registration" )
public class RegisterObj implements Serializable {
	private static final long serialVersionUID = 3924626626246812976L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	private String salutation, name, nric, badgeName, designation, company, address, postalCode;
	private String email, mobile, officeNo;
	private Integer vegetarian;
	private Integer sessionA, sessionB, sessionC, sessionD, learningJourney;

	@OneToMany(cascade= {CascadeType.ALL}, fetch=FetchType.EAGER)
	private List<ParticipantObj> participantList = new LinkedList<ParticipantObj>();

	private Double amount;
	private Date createdDate, updatedDate;
	private int paymentStatus, status, regType;
	private String payerEmail;
	
	@Transient
	private int i;
	
	public void updateWithOwnCapacity(RegisterCountObj rc, boolean isMain, int ownI) {
		if(!isMain) { //count main if it's not main
			if(sessionA>0)
				rc.getSessionA().put(sessionA, rc.getSessionA().get(sessionA)+1);
			if(sessionB>0)
				rc.getSessionB().put(sessionB, rc.getSessionB().get(sessionB)+1);
			if(sessionC>0)
				rc.getSessionC().put(sessionC, rc.getSessionC().get(sessionC)+1);
			if(sessionD>0)
				rc.getSessionD().put(sessionD, rc.getSessionD().get(sessionD)+1);
		}
		if(countParticipants()<=0)
			return;
		int i=0;
		for(ParticipantObj p: participantList) {
			if(isMain&&i==ownI) {
				i++; continue; 
			}
			if(p.getSessionA()!=null && p.getSessionA()>0)
				rc.getSessionA().put(p.getSessionA(), rc.getSessionA().get(p.getSessionA())+1);
			if(p.getSessionB()!=null && p.getSessionB()>0)
				rc.getSessionB().put(p.getSessionB(), rc.getSessionB().get(p.getSessionB())+1);
			if(p.getSessionC()!=null && p.getSessionC()>0)
				rc.getSessionC().put(p.getSessionC(), rc.getSessionC().get(p.getSessionC())+1);
			if(p.getSessionD()!=null && p.getSessionD()>0)
				rc.getSessionD().put(p.getSessionD(), rc.getSessionD().get(p.getSessionD())+1);
			i++;
		}
	}
	
	public void setCreatedDateForAll(Date createdDate) {
		if(countParticipants()<=0)
			return;
		for(ParticipantObj p: participantList) {
			p.setCreatedDate(createdDate);
		}
	}
	
	public int getParticipantCount() {
		return countParticipants();
	}
	public int getI() {
		return i;
	}
	public void setI(int i) {
		this.i = i;
	}
	public int countParticipants() {
		return participantList==null?0:participantList.size();
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getSalutation() {
		return salutation;
	}
	public void setSalutation(String salutation) {
		this.salutation = salutation;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getNric() {
		return nric;
	}
	public void setNric(String nric) {
		this.nric = nric;
	}
	public String getBadgeName() {
		return badgeName;
	}
	public void setBadgeName(String badgeName) {
		this.badgeName = badgeName;
	}
	public String getDesignation() {
		return designation;
	}
	public void setDesignation(String designation) {
		this.designation = designation;
	}
	public String getCompany() {
		return company;
	}
	public void setCompany(String company) {
		this.company = company;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPostalCode() {
		return postalCode;
	}
	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getOfficeNo() {
		return officeNo;
	}
	public void setOfficeNo(String officeNo) {
		this.officeNo = officeNo;
	}
	public Integer getVegetarian() {
		return vegetarian;
	}
	public void setVegetarian(Integer vegetarian) {
		this.vegetarian = vegetarian;
	}
	public Integer getSessionA() {
		return sessionA;
	}
	public void setSessionA(Integer sessionA) {
		this.sessionA = sessionA;
	}
	public Integer getSessionB() {
		return sessionB;
	}
	public void setSessionB(Integer sessionB) {
		this.sessionB = sessionB;
	}
	public Integer getSessionC() {
		return sessionC;
	}
	public void setSessionC(Integer sessionC) {
		this.sessionC = sessionC;
	}
	public Integer getSessionD() {
		return sessionD;
	}
	public void setSessionD(Integer sessionD) {
		this.sessionD = sessionD;
	}
	public List<ParticipantObj> getParticipantList() {
		return participantList;
	}
	public void setParticipantList(List<ParticipantObj> participantList) {
		this.participantList = participantList;
	}
	public Double getAmount() {
		return amount;
	}
	public void setAmount(Double amount) {
		this.amount = amount;
	}
	public Date getCreatedDate() {
		return createdDate;
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	public Date getUpdatedDate() {
		return updatedDate;
	}
	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}
	public int getPaymentStatus() {
		return paymentStatus;
	}
	public void setPaymentStatus(int paymentStatus) {
		this.paymentStatus = paymentStatus;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getPayerEmail() {
		return payerEmail;
	}
	public void setPayerEmail(String payerEmail) {
		this.payerEmail = payerEmail;
	}

	public Integer getLearningJourney() {
		return learningJourney;
	}

	public void setLearningJourney(Integer learningJourney) {
		this.learningJourney = learningJourney;
	}

	public int getRegType() {
		return regType;
	}

	public void setRegType(int regType) {
		this.regType = regType;
	}
	
}
